class Solution {
public:
    void reverse(string &s, int i, int j) {
        int left = i, right = j - 1;
        while (left < right) {
            swap(s[left], s[right]);
            left++, right--;
        }
        return ;
    }
    string reverseStr(string s, int k) {
        for (int i = 0; i < s.size(); i += 2 * k) {
            if (i + k <= s.size()) {
                reverse(s, i, i + k);
                continue;
            }
            reverse(s, i, s.size());
        }
        return s;
    }
};
